package com.ruoyi.cderp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.ProductionReturn;
import com.ruoyi.cderp.service.IProductionReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产退料Controller
 *
 * @author ruoyi
 * @date 2025-06-15
 */
@RestController
@RequestMapping("/system/ProductionReturn")
public class ProductionReturnController extends BaseController
{
    @Autowired
    private IProductionReturnService productionReturnService;


    /**
     * 新增时查询关于领料的相关数据
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:query')")
    @GetMapping("/query")
    public AjaxResult getInfoList(
            @RequestParam String id
    )
    {
        return success(productionReturnService.selectOrderReturnList(id));
    }



    /**
     * 查询生产退料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionReturn productionReturn)
    {
        startPage();
        List<ProductionReturn> list = productionReturnService.selectProductionReturnList(productionReturn);
        return getDataTable(list);
    }

    /**
     * 导出生产退料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:export')")
    @Log(title = "生产退料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionReturn productionReturn)
    {
        List<ProductionReturn> list = productionReturnService.selectProductionReturnList(productionReturn);
        ExcelUtil<ProductionReturn> util = new ExcelUtil<ProductionReturn>(ProductionReturn.class);
        util.exportExcel(response, list, "生产退料数据");
    }

    /**
     * 获取生产退料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(productionReturnService.selectProductionReturnById(id));
    }

    /**
     * 新增生产退料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:add')")
    @Log(title = "生产退料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionReturn productionReturn)
    {
        return toAjax(productionReturnService.insertProductionReturn(productionReturn));
    }

    /**
     * 修改生产退料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:edit')")
    @Log(title = "生产退料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionReturn productionReturn)
    {
        return toAjax(productionReturnService.updateProductionReturn(productionReturn));
    }

    /**
     * 删除生产退料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionReturn:remove')")
    @Log(title = "生产退料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productionReturnService.deleteProductionReturnByIds(ids));
    }
}
